<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script type="text/javascript">

    // 为了区分开构造器函数和其他函数的区别，应该把构造器函数的首字母大写
    function Hero(name){
        this.name = name;
        this.occupation = 'Ninja';
        this.whoAreYou = function() {
            return 'I am ' + this.name + ' and I am a ' + this.occupation;
        }
    }

    // 使用同一个构造器函数来创建不同的对象
    var h1 = new Hero('Michelanglo');
    var h2 = new Hero('Donatello');
    console.log(h1.whoAreYou());
    console.log(h2.whoAreYou());

    // 如果创建对象的时候没有使用new关键字
    var h = Hero('Leonardo');
    console.log(typeof h);
</script>
</body>
</html>
